/*
 ============================================================================
 Name        : CPU.h
 Author      : James McQueen, Corwyn Simpson, Craig Markham
 Version     :
 Date        : 05/14/2012
 Description : TCSS-422 Operating Systems Scheduler
 ============================================================================
 */

#ifndef __CPU__
#define __CPU__

#include <time.h>
#include <pthread.h>
#include "ringbuff.h"
#include "PCB.h"
#include "Scheduler.h"
/*-------------------- CPU --------------------*/

#define MAX_PROCESSES 100
#define MAX_STEPS 1000
#define DEFAULT_TICK_NS 100000000 //100ms

#define NUM_IODEVICES 4

typedef struct 
{
    Scheduler* my_scheduler;
    PCB** my_pcb_list;
    int clock_count;
    int my_num_pcb;
    struct timespec my_tick_time;
    int my_interrupted_flags[NUM_IODEVICES];
    pthread_mutex_t my_interrupt_mutex;
} CPU;

/********************* CPU Functions *********************/
CPU* cpu_init();

//places io device into interrupt queue
void cpu_interrupt(CPU* cpu, int device_num);

//add process to CPU Ready Queue
void cpu_addProcess(CPU* cpu, PCB* pcb);

//removes a process from the CPU and the Scheduler
void cpu_killProcess(CPU* cpu, int pid);

//returns the process list
PCB** cpu_getPCBList(CPU* cpu);

//returns the number of processes running on the CPU
int cpu_getProcessCount(CPU* cpu);

//starts the CPU, first process in ready queue set to run
//checks for interrupts to fix
void* cpu_run(void* cpu_pointer);

//gets a single Process from all the Processes in the system
PCB* cpu_getPCB(CPU* cpu, int process_id);

//Gets the number of clock cycles the CPU has executed
int cpu_getClock(CPU* cpu);

//Pauses and resumes the CPU thread by setting the running Process to PAUSED
void cpu_toggleRunState(CPU* cpu);

#endif /* CPU_H_ */
